import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { RewardGoodBox } from "./RewardGoodBox";
import { EReward } from "../../../../../Message/Public/EReward";
import { ItemConfig } from "../../../resource/ItemConfig";
import { ECareer } from "../../../../../Message/Public/ECareer";
import { Cache } from "../../../cache/Cache";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { RewardGoods } from "./RewardGoods";
import { RewardLabel2 } from "./RewardLabel2";
import { RewardItem } from "./RewardItem";
type int = number;
//class RewardList2
    
    export  class RewardList2 /* flash.display.Sprite */
    {
        constructor(arg1: int=200, arg2: Boolean=false)
        {
            
            mouseEnabled = false;
            this._hor = arg2;
            this._gbox = new GBox();
            if (arg2) 
            {
                this._gbox.direction = GBoxDirection.HORIZONTAL;
            }
            else 
            {
                this._gbox.direction = GBoxDirection.VERTICAL;
            }
            addChild(this._gbox);
            this._itemSprite = new RewardGoodBox(arg1);
            this._itemSprite.direction = GBoxDirection.VERTICAL;
            return;
        }

        public set horGap(arg1: int)
        {
            this._horGap = arg1;
            this._itemSprite.horGap = this._horGap;
            return;
        }

        public updateData(arg1: Array<any>, arg2: int=-1): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            this.dispose();
            var loc2=arg1.length;
            label288: while (loc1 < loc2) 
            {
                loc3 = arg1[loc1];
                var loc6=loc3.type;
                switch (loc6) 
                {
                    case EReward._ERewardItem:
                    {
                        if (!((loc5 = ItemConfig.instance.getInfoByCode(loc3.code).item).career == ECareer._ECareerNo) && !(loc5.career & Cache.instance.role.roleInfo.career)) 
                        {
                            ++loc1;
                            continue label288;
                        }
                        (loc4 = UICompomentPool.getUICompoment(RewardGoods)).updateData(loc3);
                        this._itemSprite.addItem(loc4);
                        break;
                    }
                    default:
                    {
                        (loc4 = UICompomentPool.getUICompoment(RewardLabel2)).updateData(loc3);
                        this._gbox.addChild(loc4);
                        if (loc3.type == EReward._ERewardExperience) 
                        {
                            loc4.expColor = arg2;
                        }
                    }
                }
                ++loc1;
            }
            if (this._itemSprite.numChildren > 0) 
            {
                this._itemSprite.invalidate();
                this._itemSprite.visible = false;
                this._gbox.addChild(this._itemSprite);
            }
            this._gbox.invalidate();
            addEventListener(flash.events.Event.ENTER_FRAME, this.updateItemSprite);
            return;
        }

        /* internal  */updateItemSprite(arg1: Object /* flash.events.Event */): void
        {
            var loc1;
            var loc2=((loc1 = this)._frameCount + 1);
            loc1._frameCount = loc2;
            if (this._frameCount == 2) 
            {
                this._itemSprite.visible = true;
                removeEventListener(flash.events.Event.ENTER_FRAME, this.updateItemSprite);
                this._frameCount = 0;
                if (this._itemSprite.numChildren > 0) 
                {
                    if (this._hor) 
                    {
                        this._itemSprite.y = this._itemSprite.y - 21;
                    }
                    else 
                    {
                        this._itemSprite.y = this._itemSprite.y + 4;
                    }
                }
            }
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            var loc2=null;
            removeEventListener(flash.events.Event.ENTER_FRAME, this.updateItemSprite);
            while (this._gbox.numChildren > 0) 
            {
                loc1 = this._gbox.getChildAt(0) as RewardItem;
                if (loc1 != null) 
                {
                    loc1.dispose();
                    continue;
                }
                loc2 = this._gbox.getChildAt(0) as RewardGoodBox;
                loc2.disposeChild();
                this._gbox.removeChild(loc2);
            }
            return;
        }

        public /* override */ get height(): number
        {
            var loc1=0;
            var loc3=0;
            var loc2=this._gbox.numChildren;
            while (loc1 < loc2) 
            {
                loc3 = loc3 + (this._gbox.getChildAt(loc1).height + 4);
                if (!this._hor) 
                {
                    loc3 = loc3 + this._gbox.verticalGap * 2;
                }
                ++loc1;
            }
            if (!this._hor) 
            {
                loc3 = loc3 + (8 + this._gbox.verticalGap * 2);
            }
            return loc3;
        }

        protected /* var */_gbox: GBox;

        /* internal */ /* var */_itemSprite: RewardGoodBox;

        /* internal */ /* var */_horGap: int;

        /* internal */ /* var */_hor: Boolean;

        /* internal */ /* var */_frameCount: int;
    }
